# coding:utf-8
from contextlib import nullcontext
import re
import json
from PyQt6.QtCore import Qt, QEasingCurve, QUrl
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QWidget, QVBoxLayout
from qfluentwidgets import (
    SingleDirectionScrollArea,
    SmoothScrollArea,
    ToolTipFilter,
    PixmapLabel,
    ScrollArea,
    ImageLabel,
    HorizontalPipsPager,
    PipsScrollButtonDisplayMode,
    VerticalPipsPager,
)
from qframelesswindow.webengine import FramelessWebEngineView

from views.template_chat_view import BaseInfoTemplateView
from .base_gallery_view import GalleryInterface
from .common.translator import Translator
from service.stock_service import StockMainService
from common.utils.JsonReplace import JsonPlaceholderReplacer
from config.log_config import AntLogger

class StockRealTimeView(BaseInfoTemplateView):
    """Scroll interface"""

    def __init__(self, parent=None):
        t = Translator()
        super().__init__("StockRealTimeView", parent=parent)

        # 添加一个报表
        self.addEcahtMainView("stock_real_time")

    def doSearch(self):
        AntLogger.info(f"查询股票{self.searchKey}")
        self.updateEchatData()

    def getEchatData(self, jsonData: dict):
        if self.searchKey is not None and self.searchKey != "":
            AntLogger.info(f"校验通过{self.searchKey}")
            stockService = StockMainService()
            source_data = stockService.getRealTimeStock(self.searchKey)
            replacer = JsonPlaceholderReplacer(jsonData)
            replacer.replace_placeholder("__STOCK_DATA__", source_data)
            replacer.replace_placeholder("__STOCK_NAME__", "某股票")
            AntLogger.info(f"最终解析对象{replacer.get_modified_json()}")
            return replacer.get_modified_json()
        else:
            return jsonData
